home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / FAQP9317.ZIP / 640k next >
Text File  |  1993-09-07  |  18KB  |  373 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Subject: How to access memory above 640K
  3. Followup-To: comp.os.msdos.programmer
  4. Distribution: world
  5. References: none
  6.  
  7. Last-modified: 7 Sep 1993
  8.  
  9. Part of the following material originally appeared in the FAQ list for
  10. comp.os.msdos.programmer.  However, subsequent email revealed that the
  11. answer is not really settled.  Since the FAQ list should contain
  12. "canonical best answers", I have created this separate article.  One of
  13. my rainy-day projects is to investigate this area myself.  Until then,
  14. I'm simply appending the emails and posted articles that seem relevant.
  15.  
  16. If you want your comments to be appended to this file, please be sure to
  17. email me at brown@ncoast.org.  I try to follow the newsgroup, but I may
  18. miss posted articles because c.o.m.p gets heavy traffic.
  19.  
  20. ***********************************************************************
  21. *                                                                     *
  22. *      Please do not email me with questions about this material.     *
  23. *      I don't know any more about this topic than what's below.      *
  24. *                                                                     *
  25. ***********************************************************************
  26.  
  27. The following appeared in the December 1992 FAQ list.  It is by Jamshid
  28. Afshar (jamshid@emx.utexas.edu) and incorporates comments from Duncan
  29. Murdoch (dmurdoch@mast.queensu.ca).
  30.  
  31.     1. Use XMS or EMS memory.  XMS is preferable in most cases, but
  32.     some machines won't provide it.  There are some libraries available
  33.     at Simtel to access XMS or EMS.  The disadvantage is that you
  34.     don't allocate the memory as you would with malloc() (or `new' in
  35.     C++).  I believe it also requires that you lock this memory when in
  36.     use.  This means your code is not easily ported to other (and
  37.     future) operating systems and that your code is more convoluted than
  38.     it would be under a "real" os.  The advantage is that the library
  39.     works with compilers since Turbo C 2.0 (I think) and that your
  40.     program will easily run on even 286s.
  41.  
  42.     2.  Program under MS Windows.  MS Windows functions as a 16-bit DOS
  43.     Extender (see #3).  Borland/Turbo C++ 3.x includes EasyWin [and
  44.     Microsoft C/C++ 7.0 has QuickWin --ed.] which is a library that
  45.     automatically lets you compile your current code using C/C++
  46.     standard input or <conio.h> into a MS Windows program so your code
  47.     can immediately allocate many MBs of memory (Windows enhanced mode
  48.     even does virtual memory).  The disadvantage is that like any 16-bit
  49.     Extender a single malloc() is restricted to 64K (unless you want to
  50.     mess with huge pointers in Windows).  Also, EasyWin's screen output
  51.     is significantly slower than a DOS character-mode program's and you
  52.     must of course run the program from Windows.
  53.  
  54.     3.  Use a 16-bit or 32-bit DOS Extender.  This is definitely the
  55.     best solution from the programmer's standpoint.  You just allocate
  56.     as much memory as you need using malloc() or 'new'.  A 16-bit
  57.     Extender still has 16-bit ints and restricts arrays to 64K, but a
  58.     32-bit Extender has 32-bits ints (which makes porting a lot of UNIX
  59.     code easier) so there are no 64K limits.  A 32-bit Extender requires
  60.     a 32-bit compiler and the program will not run on 286s.  Some
  61.     Extenders also do virtual memory.  Using an Extender doesn't require
  62.     source code changes and unlike option #1 your code is portable and
  63.     not obsolete in a few months.  Your options for this solution are:
  64.  
  65.     - Buy PharLap's 16-bit Extender that works with BC++ 3.0+ and MSC
  66.       (just requires a relink).  Note, the BC++ 3.1 upgrade came with
  67.       PharLap "lite".  Pharlap's 32-bit Extender works with 32-bit
  68.       compilers like [?]
  69.  
  70.     - Get the GNU (free,copylefted) gcc 2.x compiler which DJ Delorie
  71.       ported from UNIX and which uses his 32-bit Extender.  It supports
  72.       C and C++, but the Extender is VCPI which means neither the
  73.       compiler nor programs it produces will run in a DOS session under
  74.       Windows.  FTP to barnacle.erc.clarkson.edu and get
  75.       pub/msdos/djgpp/readme.  [See updates in messages of 9 April
  76.       and 27 June.--ed.]
  77.  
  78.     - Get a 32-bit compiler or one that comes with a DOS Extender.
  79.       Zortech comes with 16-bit and a 32-bit Extenders (no debugger for
  80.       32-bit programs, but Flashtek sells one).  Watcom also makes a C
  81.       [and C++?] 32-bit compiler.  [If anyone else has products or plans
  82.       to announce, please let me know.]
  83.  
  84.     - Buy Borland Pascal 7.0.  It includes a 16 bit royalty-free DOS
  85.       extender using the same interface as MS Windows.  It functions
  86.       under a DPMI server like Windows or QDPMI from Quarterdeck, and
  87.       also provides its own server which you can distribute with your
  88.       programs.
  89.  
  90.     4.  This option doesn't really count since it's not a solution in
  91.     DOS, but you could switch to a full 32-bit operating system like
  92.     OS/2 2.0 or UNIX (or NT when it comes out).  I believe Win32 will
  93.     allow you to write 32-bit Windows programs.  (Can someone fill me in
  94.     on what exactly Win32 is?)  [ed.note:  See message of 13 May below.]
  95.  
  96.  
  97. Date: Mon, 21 Dec 92 08:36:50 -0500
  98. From: malak@grebyn.com (Michael Malak)
  99. Message-Id: <9212211336.AA02279@daily.grebyn.com>
  100.  
  101.     You should also mention the Intel 386/386 C Code Builder Kit.  It is
  102.     a 32-bit C compiler, linker, and 32-bit DOS extender.  It is the
  103.     _only_ 32-bit DOS extender that allows you to link in 32-bit MASM
  104.     6.0 modules, thus obviating the need to buy Phar Lap's assembler and
  105.     be stuck with its archaic MASM 4.x syntax.  All for a list price of
  106.     $595.
  107.  
  108.  
  109. Date: Thu, 24 Dec 92 13:45:40 EST
  110. From: dmurdoch@mast.QueensU.CA (Duncan Murdoch)
  111. Message-Id: <9212241845.AA23280@mast.mast.QueensU.CA>
  112.  
  113.     I don't know anything about the Intel package, but certainly
  114.     wouldn't object to putting the information in.  I'd delete the claim
  115.     that it's the only package to link MASM code; that may be true, but
  116.     isn't likely to last for long.
  117.  
  118.  
  119. Date: Wed, 27 Jan 1993 23:25:12 GMT
  120. From: gah@trc.mew.mei.co.jp (Gary A. Hildebrand)
  121. Subject: Re: Accessing mem above 1 meg???
  122. Message-ID: <GAH.93Jan28082512@trcrik.trc.mew.mei.co.jp>
  123.  
  124. >>>>> ">" == Ernest Ong <ernie@tartarus.uwa.edu.au> writes:
  125. >> Does anyone know how to access memory above 1 meg on a 386 machine???
  126. >> without switching to protected mode
  127. >> ie in real mode & using linear addressing (bypassing MMU).
  128.  
  129. Although you can use 386-style 32-bit effective addresses in real mode (by
  130. specifying the appropriate instruction prefix of 0x67), they are still
  131. limited to a maximum value of (64KB - 1).  This is because the segment
  132. limit cached into each and every segment register is (64KB - 1) when in
  133. real mode.  It would be impossible to change these limits without switching
  134. to protected mode and reloading the segment register, and would have
  135. unpredictable results back in real mode.  If you do exceed a segment limit
  136. in real mode, it will generate an exception, which will hang most machines
  137. because the real-mode BIOS usually cannot distinguish an exception specific
  138. to a 286 or higher processor from a hardware/software interrupt, and
  139. doesn't know how to recover.  So basically, you *can't* do the above!
  140.  
  141. But there is a tricky way to get a little less than 64KB of additional
  142. memory in real mode, which is the basis for the HMA (High Memory Area)
  143. specification.  It is possible, even with 16-bit offset and segment values
  144. in real mode, to create an address greater than 1MB.  Consider the far
  145. address 0xFFFF:0xFFFF.  The corresponding linear address would be 0x10FFEF,
  146. clearly above 1MB.  The 386, like the 286, will not wrap this address
  147. around to 0xFFEF the way the 8086/88/186 does, given the larger address
  148. bus.  And this address doesn't violate segment limits set for real mode.
  149.  
  150. There are a few gotchas with using the HMA.  For one, most PC-compatible
  151. systems by default deliberately disable address lines A20 (and above?) to
  152. protect 8086 software (sometimes including the BIOS itself) which *expect*
  153. wraparound to occur past 1MB.  Before using the HMA, you must enable A20,
  154. and the method varies from system to system.  True AT-compatibles, PS/2's,
  155. HP Vectras, and AT&T 6300's all use different methods, some of them truly
  156. bizarre, in order to really protect this line from casually being changed.
  157. On an AT-compatible, the A20 gate is enabled using the 8042 keyboard
  158. controller, of all things!
  159.  
  160. Another has to do with normalization of far pointers.  To normalize means
  161. to set up the segment and offset so that there are no overlapping set bits
  162. between them, and is handy for "uniqueifying" an address.  The problem with
  163. this is that it breaks the HMA, since you can't go above 1MB with a
  164. normalized address!  So be wary of DOS functions which might want to
  165. normalize your pointer first.
  166.  
  167. Good luck!
  168.  
  169.  
  170. From: usenet.INS.CWRU.Edu!logicraft.com!lacroix (Scott LaCroix)
  171. Message-Id: <9302091954.AA04224@logicraft.com>
  172.  
  173.     The Zortech compiler I have (I'm not sure of the version, it's at
  174.     home) does C and C++, comes with a 16 and 32 bit extander, and a 32
  175.     bit debugger.  (Although, I can't vouch for the debugger, my install
  176.     disk was a little flaky and as a result the debugger doen't work
  177.     quite right...)  Also, I beleive the Watcom compiler DOES do C++.
  178.  
  179.     As a side note, both the Watcom and the Zortech compilers have
  180.     Windows libraries available and their debuggers will run under
  181.     Windows.
  182.  
  183.     My money (by FAR) is on the Watcom set.  It costs more, but the
  184.     functionality is phenomenal!  I wrote a 32 bit, TCPIP, Windows 3.1
  185.     app with the 16-32 bit conversion tools provided standard with it,
  186.     and I don't think I could do the same with Zortech.  (Just as a
  187.     note, I used FTP Software's TCPIP package...)
  188.  
  189.  
  190. From: usenet.INS.CWRU.Edu!pharlap.com!jim (James E. Phillips)
  191. Date: Mon, 15 Mar 93 13:43:03 EST
  192. Message-Id: <9303151843.AA04998@pharlap.pharlap.com>
  193.  
  194.     [ed. note:  Phillips works for Phar Lap, which is the "our" in the
  195.     text below]
  196.  
  197.     Just trying to correct a couple of things that were either incorrect
  198.     or misleading (I got misled) in the recent posting to the newsgroup.
  199.     Feel free to spread the word along, along with my e-mail address.
  200.  
  201.     Most 16-bit extenders, the Phar Lap 286|DOS-Extender among them,
  202.     allow you to allocate arrays larger than 64K by using the "huge"
  203.     keyword, and special malloc() functions like halloc() (MSC) or
  204.     farmalloc() (Borland).  This is the same thing that people do under
  205.     MS-DOS to create arrays larger than 64K.
  206.  
  207.     Our 286|DOS-Extender "officially" works with Borland 2.0, 3.0 and
  208.     3.1, Microsoft C 5.1, 6.0, 6.0a and 7.0, and Microsoft Fortran 5.0
  209.     and 5.1.
  210.  
  211.     Some applications may require source code changes, but the
  212.     modifications are in many cases relatively minor.
  213.  
  214.     The 386|DOS-Extender works with a number of 32-bit compilers like
  215.     Metaware High C/C++, Watcom C/386 and Microsoft's NT compiler.
  216.  
  217.     Our 386|DOS-Extender will accept 32-bit modules from MASM 6.0, and
  218.     has for the last three versions.  Our own 386|ASM is still MASM 4.x
  219.     compatible, however.
  220.  
  221.     I should also point out that our extenders will run fine under
  222.     MS-DOS, Windows or OS/2 2.0 (and we have our fingers crossed for Win
  223.     NT...).
  224.  
  225.  
  226. Date: Fri, 9 Apr 93 10:04:55 EDT
  227. From: DJ Delorie <usenet.INS.CWRU.Edu!ctron.com!dj>
  228. Message-Id: <9304091404.AA26988@delorie.ctron>
  229.  
  230.     Please change the reference for djgpp from barnacle.erc.clarkson.edu
  231.     to omnigate.clarkson.edu (it moved).
  232.  
  233.  
  234. Date: Sun, 19 Apr
  235. From: Stan Brown <brown@ncoast.org>
  236.  
  237.     You may want to browse through the Simtel directories.  Files such
  238.     as the following look promising, though I haven't explored them
  239.     myself:
  240.  
  241.     pd1:<msdos.turbo-c>xmsif142.zip  XMS interface for Borland/MS C[++]
  242.  
  243.  
  244. Date: Sun, 25 Apr 93 17:13:08 -0700
  245. From: Darryl Okahata <darrylo@hpnmxx.sr.hp.com>
  246. Message-Id: <9304260013.AA03077@hpnmxx.sr.hp.com>
  247.  
  248.     Here's another plug for the WATCOM C/386 32-bit compiler.  While
  249.     it's not perfect (it's entirely command-line based -- there's no
  250.     IDE), it's an ANSI C compiler that produces 32-bit code for MSDOS,
  251.     MS Windows, or OS/2.  It also comes with 32-bit debuggers for MSDOS,
  252.     MS Windows, and OS/2, and supports remote debugging via a serial
  253.     port, parallel port, Novell network, or NetBIOS.  The debuggers,
  254.     while somewhat primitive, are more than enough to get the job done.
  255.  
  256.     WATCOM C/386 comes with 32-bit Windows libraries (along with SDK
  257.     programs licensed from Microsoft), and a graphics library for plain
  258.     MSDOS programs.  Interestingly enough, the MSDOS graphics library
  259.     uses Windows .FON fonts, and has some support for SVGA modes.
  260.  
  261.     The 32-bit DOS extender does *NOT* require any special memory
  262.     managers (like QEMM, EMM386, or 386MAX), unlike some other
  263.     extenders, and will work within an MS Windows DOS window.  The
  264.     bottom line is that you can run 32-bit MSDOS programs within a DOS
  265.     Window.  Outside of MS Windows, the DOS extender allows you to have
  266.     virtual memory, so that your 32-bit program will run on machines
  267.     with limited memory.  Unfortunately, I believe that the extender has
  268.     a limit of 32MB of addressable memory.
  269.  
  270.     Best of all, the DOS extender is royalty-free.  I believe PharLap's
  271.     extender requires royalty payments, which is why I don't use
  272.     PharLap's extender.
  273.  
  274.     I've used WATCOM C/386 to port both Perl 4.0pl36 and GNU Emacs to
  275.     MSDOS.  Both of these are LARGE programs, and the ports went
  276.     amazingly smoothly.  While doing the ports was not simple, I didn't
  277.     find any compiler bugs, although I did find some minor problems with
  278.     the DOS extender.  (Note:  don't ask me for a copy of these
  279.     programs; both of them are available from Simtel20 and mirror sites,
  280.     so look there.)
  281.  
  282.     WATCOM has not yet released its C/C++ compiler (supposedly, "in a
  283.     couple of months").  However, people who currently own WATCOM C/386
  284.     can purchase an early version of their forthcoming C/C++ compiler.
  285.  
  286.     While the WATCOM C/386 compiler is an excellent one, it's not
  287.     without its "warts".  If anyone wants a slightly more detailed
  288.     review of WATCOM C/386 (one that talks a bit more about the
  289.     "warts"), send email [ed.note: to darrylo@hpnmxx.sr.hp.com, not me].
  290.  
  291.  
  292. Date: Thu, 13 May 93 16:22:02 +0200
  293. From: Ian Johnston US/ESS <johnston@mailhost.us-es.sel.de>
  294. Message-Id: <9305131422.AA21590@slsvist.us-es.sel.de>
  295.  
  296.     Win32s was described in a recent MS Systems Journal (I'm working in
  297.     Germany right now, so it may be a bit behind, and I don't have the
  298.     reference handy, sorry).
  299.  
  300.     My understanding of Win32s is this:  it is a 'thin layer' API
  301.     wrapper around 16-bit Windows.  You write a 32-bit Windows
  302.     application (in fact, in the MSJ article, it was suggested that
  303.     Windows/NT is a good host for this!), and then run it on 16-bit
  304.     Windows.  The Win32s (sub-)system will then:
  305.  
  306.     - hook into the program loading process.  Basically, the Win16
  307.       program loader in the kernel realises it doesn't recognise the
  308.       executable format, and makes a call to a handler routine.  Win32s
  309.       hooks this routine, checks if the executable is actually a 32-bit
  310.       Windows app, and if so, loads it.
  311.  
  312.     - provide a thin API which translates 32-bit versions of Windows API
  313.       calls into their 16 bit equivalents, and translate the 16-bit
  314.       results from Windows back into the 32-bit results your app is
  315.       expecting.
  316.  
  317.     - provide some memory management features (my recollection of this
  318.       is a bit hazy) which will manage Windows memory, making it look
  319.       like a flat 32-bit address space to your app.
  320.  
  321.     There are some caveats with this.  Obviously, Win16 doesn't provide
  322.     all the facilities that Windows/NT does, such as pre-emptive multi-
  323.     tasking, or threads.  So Windows/NT apps using those facilities
  324.     won't run under Win32s.  On the other hand, an app that restricts
  325.     itself to the kind of facilities present in Windows anyway will
  326.     (should?) run quite happily under Win32s.
  327.  
  328.     The app doesn't need to know whether it is running on Windows/NT or
  329.     under Win32s.  Some system query calls are provided for apps which
  330.     need to know which system they are actually running on.  The Win32s
  331.     layer actually exports all the APIs present in Windows/NT (although
  332.     of course some of them are no-ops), so that applications can load
  333.     under Win32s, without problems caused by otherwise non-existent
  334.     entry points.  This means that it is actually possible to write an
  335.     app which checks the system it is running on, and uses NT-specific
  336.     routines if running on NT, and if running on Win32s, either uses
  337.     Windows versions of those routines or switches out some part of its
  338.     functionality.
  339.  
  340.  
  341. Date: Sun, 27 Jun 93 12:23:51 CDT
  342. From: "Jeremy Mathers" <usenet.INS.CWRU.Edu!midway.uchicago.edu!pynq>
  343. Message-Id: <9306271723.AA09648@midway.uchicago.edu>
  344.  
  345.     Just a small note:  As of DJGPP version 1.10 (released 6/1/93), DPMI
  346.     *is* supported.  So, it can be run (both the compiler/linker and the
  347.     programs it generates) inside a DOS box under either Windows or
  348.     OS/2.
  349.  
  350.     Note:  I haven't actually verified this myself since I stopped using
  351.     DJGPP when I switched over to OS/2 (there are native OS/2 GCC ports
  352.     that work a heck of a lot better than DJGPP does), but I still read
  353.     the DJGPP mailing list.
  354.  
  355.     Also, DJGPP 1.10 is kind of an interim release.  1.11 is due out RSN
  356.     and is supposed to be a lot more stable (particularly with respect
  357.     to the DPMI support).
  358.  
  359.  
  360. Date: Wed, 1 Sep 93 18:02:34 -0700
  361. From: boutell@netcom.com (Thomas Boutell)
  362. Message-Id: <9309020102.AA19042@netcom.netcom.com>
  363.  
  364.     Oh, under your list of "solutions" based on a new OS (NT or OS/2),
  365.     list Linux!  It's free, it works, and it ain't Microsoft or IBM
  366.     kludge.
  367.  
  368. -----
  369.  
  370. A reminder:  I don't know enough to evaluate what people say above, so
  371. if you have a beef with any of it, take it up with them not me.
  372.  
  373.